// index.js

import {
	createStore
} from 'vuex';

export default createStore({
	state: {
		tabIndex: 0,
		selectAddr: '',
		currentUserDatas: '',
		districtId: -100, //-100 未选择   -1 不在服务区
		choosePosition: 1, //1 报修  2保养
		clickOrderStailsId: -100,//点击查看工单详情的工单ID
		clickOrderStailsmachineModelNumber:"",//点击查看工单详情的工单中的设备型号
	},
	actions: {
		// 使用commit来调用mutation中的方法
		setAddrAsync({
			commit
		}, payload) {
			commit('setAddr', payload)
		},
		setCurrentUserDatasAsync({
			commit
		}, payload) {
			commit('setCurrentUserDatas', payload)
		},
		setDistrictIdAsync({
			commit
		}, payload) {
			commit('setDistrictId', payload)
		},
		setChoosePositionAsync({
			commit
		}, payload) {
			commit('setChoosePosition', payload)
		},
		setClickOrderStailsIdAsync({
			commit
		}, payload) {
			commit('setClickOrderStailsId', payload)
		},
		setClickOrderStailsmachineModelNumberAsync({
			commit
		}, payload) {
			commit('setClickOrderStailsmachineModelNumber', payload)
		},
		setTabIndexAsync({
			commit
		}, payload) {
			commit('setTabIndex', payload)
		},
	},
	mutations: {
		setCurrentUserDatas(state, payload) {
			state.currentUserDatas = payload;
		},
		setDistrictId(state, payload) {
			state.districtId = payload;
		},
		setAddr(state, payload) {
			state.selectAddr = payload;
		},
		setChoosePosition(state, payload) {
			state.choosePosition = payload;
		},
		setClickOrderStailsId(state, payload) {
			state.clickOrderStailsId = payload;
		},
		setClickOrderStailsmachineModelNumber(state, payload) {
			state.clickOrderStailsmachineModelNumber = payload;
		},
		setTabIndex(state, payload) {
			state.tabIndex = payload;
		},
	},

	getters: {
		// 获取计算属性
		getTabIndex: (state) => state.tabIndex,
		// getSelectAddr: (state) => state.selectAddr,
		getSelectAddr(state) {
			return state.selectAddr;
		},
		getCurrentUserDatas: (state) => state.currentUserDatas,
		getDistrictId: (state) => state.districtId,
		getChoosePosition: (state) => state.choosePosition,
		getClickOrderStailsId: (state) => state.clickOrderStailsId,
		getClickOrderStailsmachineModelNumber: (state) => state.clickOrderStailsmachineModelNumber,
	},
});
